package com.gosling.cloudspace.config.mybatis;

import io.swagger.annotations.Api;
import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

@Api("分页参数")
@Data
public class PageParam implements Serializable {

    private static final Long PAGE_NO = 1L;
    private static final Long PAGE_SIZE = 10L;

    private Long offset;
    @NotNull(message = "页码不能为空")
    @Min(value = 1, message = "页码最小值为 1")
    private Long pageNo = PAGE_NO;
    @NotNull(message = "每页条数不能为空")
    @Min(value = 1, message = "每页条数最小值为 1")
    @Max(value = 1000, message = "每页条数最大值为 1000")
    private Long pageSize = PAGE_SIZE;

    public Long getOffset() {
        return (pageNo - 1) * pageSize;
    }

}
